package io.yunho.webflux.client.config;

import io.yunho.webflux.client.interfaces.ProxyCreator;
import io.yunho.webflux.client.service.IUser;
import io.yunho.webflux.client.service.JdkProxyCreator;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author: yunho
 * @date: 2021/5/15 9:25
 * @description:
 */
@Configuration
public class FactoryBeanConfig {
    @Bean
    public ProxyCreator proxyCreator(){
        return new JdkProxyCreator();
    }
    @Bean
    FactoryBean<IUser> userApi(ProxyCreator proxyCreator){
        return new FactoryBean<IUser>() {
            //返回代理对象
            @Override
            public IUser getObject() throws Exception {
                return (IUser) proxyCreator.createProxy(this.getObjectType());
            }

            @Override
            public Class<?> getObjectType() {
                return IUser.class;
            }
        };
    }
}
